package com.app.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.view.MotionEvent;
import android.view.View;

public class HandWritingView extends View {

	Path path = null;
	Paint paint = null;
	
	public HandWritingView(Context context) {
		super(context);
		path = new Path();
		paint = new Paint();
		
		paint.setColor(Color.YELLOW);
		paint.setStyle(Style.STROKE);
		paint.setStrokeWidth(10.0f);
		paint.setAntiAlias(true);
		this.setBackgroundColor(Color.WHITE);
	}

	
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if(event.getAction() == MotionEvent.ACTION_DOWN){
			float x = event.getX();
			float y = event.getY();
			path.moveTo(x, y);
			invalidate();
			System.out.println("path--------->"+x + "," +y);
			return true;
		}else if(event.getAction() == MotionEvent.ACTION_MOVE){
			float x = event.getX();
			float y = event.getY();
			path.lineTo(x, y);
			invalidate();
			System.out.println("path--------->"+x + "," +y);
			return true;
		}
		return super.onTouchEvent(event);
	}



	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		if (path != null) {
			canvas.drawPath(path, paint);
			System.out.println("onDraw--------->");
		}
	}

}
